function FindProxyForURL(url, host) {
  var proxy = "PROXY 127.0.0.1:7897; SOCKS5 127.0.0.1:7897";
  var direct = "DIRECT";

  // =====================
  // 局域网 / 本地直连（优化版）
  // =====================
  if (isPlainHostName(host) ||
      isInNet(host, "127.0.0.0", "255.0.0.0") ||
      isInNet(host, "10.0.0.0", "255.0.0.0") ||
      isInNet(host, "192.168.0.0", "255.255.0.0") ||
      isInNet(host, "172.16.0.0", "255.240.0.0") ||
      shExpMatch(host, "::1") ||
      shExpMatch(host, "fe80:*") ||
      shExpMatch(host, "*.local") ||
      shExpMatch(host, "localhost")
  ) {
    return direct;
  }

  // =====================
  // 中国大陆域名直连
  // =====================
  var directDomains = [
    // 电商平台
    "taobao.com",
    "tmall.com",
    "1688.com",
    "aliyun.com",
    "aliexpress.com",
    "jd.com",
    "jdpay.com",
    "360buy.com",
    "pinduoduo.com",
    "pdd.com",
    "suning.com",
    "snssdk.com",
    "vip.com",
    "vipshop.com",
    "dangdang.com",
    "vancl.com",
    "yhd.com",
    "yihaodian.com",
    "gome.com.cn",
    "fliggy.com",
    "kaola.com",
    "yanxuan.com",
    "dewu.com",
    "poizon.com",

    // 社交媒体和通讯
    "qq.com",
    "qzone.qq.com",
    "tencent.com",
    "weixin.qq.com",
    "wx.qq.com",
    "weibo.com",
    "sina.com.cn",
    "t.cn",
    "douyin.com",
    "toutiao.com",
    "bytedance.com",
    "xiaohongshu.com",
    "xhscdn.com",
    "zhihu.com",
    "zhimg.com",
    "tieba.baidu.com",
    "hao123.com",
    "momo.com",
    "immomo.com",
    "soul-plus.com",
    "soulapp.cn",

    // 视频平台
    "youku.com",
    "tudou.com",
    "soku.com",
    "iqiyi.com",
    "qiyi.com",
    "qy.net",
    "bilibili.com",
    "bilivideo.com",
    "hdslb.com",
    "douyu.com",
    "douyucdn.cn",
    "huya.com",
    "msstatic.com",
    "acfun.cn",
    "aixifan.com",
    "le.com",
    "letv.com",
    "sohu.com",
    "tv.sohu.com",
    "pptv.com",
    "pp.tv",
    "56.com",
    "v.163.com",
    "xigua.com",
    "ixigua.com",
    "kuaishou.com",
    "yximgs.com",
    "mgtv.com",
    "hunantv.com",

    // 搜索引擎
    "baidu.com",
    "bdstatic.com",
    "bdimg.com",
    "bcebos.com",
    "sogou.com",
    "soso.com",
    "so.com",
    "360.cn",
    "360.com",
    "qihoo.com",
    "sm.cn",
    "uc.cn",
    "youdao.com",
    "dict.youdao.com",

    // 新闻媒体
    "xinhuanet.com",
    "news.cn",
    "people.com.cn",
    "peopleapp.com",
    "cctv.com",
    "cntv.cn",
    "cctvnews.cctv.com",
    "chinadaily.com.cn",
    "china.org.cn",
    "thepaper.cn",
    "caixin.com",
    "caijing.com.cn",
    "ifeng.com",
    "phoenix.com",
    "huanqiu.com",
    "globaltimes.cn",
    "163.com",
    "netease.com",
    "126.com",
    "sina.com",
    "sina.cn",
    "eastmoney.com",
    "stockstar.com",
    "cnr.cn",
    "cri.cn",
    "gmw.cn",
    "guangming.com.cn",
    "ce.cn",
    "jjckb.cn",
    "chinanews.com",

    // 金融服务
    "alipay.com",
    "ant.design",
    "antgroup.com",
    "icbc.com.cn",
    "ccb.com",
    "boc.cn",
    "abchina.com",
    "cmbchina.com",
    "cmbc.com.cn",
    "cib.com.cn",
    "spdb.com.cn",
    "cgbchina.com.cn",
    "bankcomm.com",
    "pingan.com",
    "ping-an.com",
    "lufax.com",
    "lu.com",
    "1234567.com.cn",
    "fund123.cn",
    "howbuy.com",
    "xueqiu.com",
    "snowballsecurities.com",

    // 出行交通
    "12306.cn",
    "china-railway.com.cn",
    "ctrip.com",
    "ctripimg.com",
    "elong.com",
    "qunar.com",
    "qunarzz.com",
    "tuniu.com",
    "tuniucdn.com",
    "ly.com",
    "mangocity.com",
    "mafengwo.cn",
    "mfwcdn.com",
    "amap.com",
    "autonavi.com",
    "didi.com.cn",
    "didiglobal.com",
    "xiaojukeji.com",
    "uber.com.cn",
    "t3go.cn",
    "hellobike.com",
    "mobike.com",
    "carhome.com.cn",
    "autohome.com.cn",
    "che168.com",
    "yiche.com",
    "bitauto.com",
    "pcauto.com.cn",

    // 本地生活
    "meituan.com",
    "meituan.net",
    "dianping.com",
    "dpfile.com",
    "ele.me",
    "eleme.cn",
    "58.com",
    "anjuke.com",
    "ganji.com",
    "fang.com",
    "soufun.com",
    "soufunimg.com",
    "lianjia.com",
    "ke.com",
    "ziroom.com",
    "danke.com",

    // 招聘求职
    "zhaopin.com",
    "zhaopin.com.cn",
    "51job.com",
    "yjbys.com",
    "liepin.com",
    "liepin.cn",
    "lagou.com",
    "3g.lagou.com",
    "boss.com",
    "bosszhipin.com",
    "jobui.com",
    "maimai.cn",

    // 教育学习
    "xuetangx.com",
    "edx.org.cn",
    "icourse163.org",
    "study.163.com",
    "zhenguanxi.com",
    "imooc.com",
    "koolearn.com",
    "xdf.cn",
    "vipkid.com",
    "dadaabc.com",
    "yuanfudao.com",
    "fenbi.com",
    "duolingo.cn",
    "gaosan.com",
    "eol.cn",
    "chsi.com.cn",
    "neea.edu.cn",

    // 技术开发
    "csdn.net",
    "iteye.com",
    "cnblogs.com",
    "cnblog.com",
    "oschina.net",
    "oscimg.oschina.net",
    "segmentfault.com",
    "sf-static.com",
    "juejin.cn",
    "juejin.im",
    "v2ex.com",
    "ruby-china.org",
    "gitee.com",
    "gitee.io",
    "gitcode.com",
    "coding.net",
    "coding.io",
    "teambition.com",
    "dingtalk.com",
    "tapd.cn",
    "ones.ai",
    "Tower.im",
    "worktile.com",
    "shimo.im",
    "kdocs.cn",
    "wps.cn",
    "lanhuapp.com",
    "mockplus.cn",
    "processon.com",
    "draw.io",

    // 云服务
    "aliyuncs.com",
    "alicdn.com",
    "qcloud.com",
    "myqcloud.com",
    "tencentcloudapi.com",
    "huaweicloud.com",
    "huawei.com",
    "baidubce.com",
    "ucloud.cn",
    "upyun.com",
    "qiniu.com",
    "qiniucdn.com",
    "163yun.com",

    // 游戏娱乐
    "steam.com.cn",
    "steamstatic.com.cn",
    "taptap.com",
    "taptapdada.com",
    "4399.com",
    "7k7k.com",
    "17173.com",
    "178.com",
    "nga.cn",
    "ngacn.cc",
    "ali213.net",
    "gamersky.com",
    "yzz.cn",
    "yingyongbao.com",
    "wandoujia.com",
    "shouji.baidu.com",
    "miui.com",
    "mi.com",
    "oppo.com",
    "oneplus.com",
    "vivo.com.cn",
    "iqoo.com",
    "meizu.com",
    "flyme.cn",

    // 政府机构
    "gov.cn",
    "mofcom.gov.cn",
    "miit.gov.cn",
    "stats.gov.cn",
    "ndrc.gov.cn",
    "moe.gov.cn",
    "edu.cn",
    "pku.edu.cn",
    "tsinghua.edu.cn",
    "ncepu.edu.cn",
    "customs.gov.cn",
    "safe.gov.cn",
    "pbc.gov.cn",
    "csrc.gov.cn",
    "chinatax.gov.cn",
    "tax.gov.cn",
    "12333.gov.cn",
    "saic.gov.cn",
    "samr.gov.cn",
    "nhsa.gov.cn",
    "mos.gov.cn",
    "lottery.gov.cn",
    "cwl.gov.cn",
    "baoding.gov.cn",

    // 医疗健康
    "haodf.com",
    "chunyu.com",
    "dxy.cn",
    "dxy.com",
    "39.net",
    "familydoctor.com.cn",
    "120ask.com",
    "fh21.com.cn",
    "jiankang.com",
    "bohe.com",
    "mint.com",
    "boohee.com",
    "keep.com",
    "gotokeep.com",

    // 物流快递
    "sf-express.com",
    "sf-express.com.cn",
    "sto.cn",
    "zto.com",
    "yto.net.cn",
    "yunda.com",
    "ems.com.cn",
    "11183.com.cn",
    "jdwl.com",
    "cainiao.com",
    "kuaidi100.com",
    "17track.net",

    // 工具应用
    "aizhan.com",
    "chinaz.com",
    "ip138.com",
    "ipip.net",
    "tianqi.com",
    "weather.com.cn",
    "nmc.cn",
    "cma.gov.cn",
    "pconline.com.cn",
    "zol.com.cn",
    "it168.com",
    "yesky.com",
    "mydrivers.com",
    "ithome.com",
    "feng.com",
    "smzdm.com",
    "zdm.com",

    // 文档办公
    "shimowendang.com",
    "yozosoft.com",
    "jinshuju.net",
    "form.mikecrm.com",
    "ding.talk",
    "feishu.cn",
    "larkoffice.com",
    "tencent-meeting.com",
    "voovmeeting.com",
    "zoom.com.cn",
    "zhumu.com",

    // 设计素材
    "iconfont.cn",
    "alibaba.com",
    "699pic.com",
    "16pic.com",
    "90sheji.com",
    "zcool.com.cn",
    "ui.cn",
    "uisdc.com",

    // 原有域名保持
    "lawporter.com",
    "chainmaker.org.cn",
    "cicc.org.cn",
    "cnki.net",
    "chazidian.com",
    "douban.com",
    "doyo.cn",
    "eastday.com",
    "hnair.com",
    "hupu.com",
    "diyifanwen.com",
    "ddooo.com",
    "donews.com",
    "dict.cn",
    "danceinchina.org",
    "doc88.com",
    "docin.com",
    "downcc.com",
    "huolala.cn",
    "hongxiu.com",
    "hujiang.com",
    "huatu.com",
    "icauto.com.cn",
    "kingsoft.com",
    "iciba.com",
    "jjwxc.net",
    "jianshu.com",
    "javatt.top",
    "tianyancha.com",
    "wanfangdata.com.cn",
    "ximalaya.com",
    "xzw.com",
    "yundaex.com",
    "hexun.com",
    "tvmao.com",
    "k366.com",
    "ruiwen.com",
    "lenovo.com",
    "kugou.com",
    "kuwo.cn",
    "jia.com",
    "zte.com.cn",
    "mama.cn",
    "redcross.org.cn",
    "qqtn.com",
    "qcc.com",
    "meipian.cn",
    "npmmirror.com",
    "onlinedown.net",
    "maigoo.com",
    "mnw.cn",
    "qidian.com",
    "zdic.net",
    "zhyyzx.com",
    "deepseek.com",
    "cngold.org",
    "cstm.org.cn",
    "cfaa.cn",
    "ccas.com.cn",
    "caanet.org.cn",
    "bendibao.com",
    "apple.com.cn",
    "51test.net",
    "1905.com",
    "189.cn",
    "10086.cn",
    "petalmail.com",
    "dcloud.io",
    "dcloud.net.cn",
    "cli.im",
    "dengbsc.com",
    "cn.element-plus.org",
    "opentiny.design",
    "fanyu.com",
  ];

  // =====================
  // 域名匹配
  // =====================
  for (var i = 0; i < directDomains.length; i++) {
    if (dnsDomainIs(host, directDomains[i])) {
      return direct;
    }
  }

  // =====================
  // 默认策略
  // =====================
  return proxy + "; " + direct;
}
